package com.example.blogdesign.Controller;


import com.example.blogdesign.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.example.blogdesign.utils.FileUtility.deleteImg;
import static com.example.blogdesign.utils.FileUtility.uploadImg;

@Slf4j
@RestController
@RequestMapping("upload")
public class UploadController {

    @PostMapping("blog")
    public Result<?> uploadImage(@RequestParam("file") MultipartFile image) {
        String fileName = uploadImg(image);
        return Result.ok((Object) fileName);
    }

    @GetMapping("/blog/delete")
    public Result<Boolean> deleteBlogImg(@RequestParam("name") String filename) {
        boolean success = deleteImg(filename);
        return Result.ok(success);
    }

}
